package com.justnow.offer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author justnow
 * Created on 2020-09-21
 * Description
 *
 * 全排列方法一，基于used数组的
 */
public class Leetcode46_Permute01 {
    List<List<Integer>> res = new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
        int length = nums.length;
        boolean[] used = new boolean[length];
        List<Integer> path = new ArrayList<>();
        dfs(nums, 0, path, used);
        return null;
    }



    private void dfs(int[] nums, int depth, List<Integer> path, boolean[] used) {
        if (depth == nums.length - 1) {
            res.add(new ArrayList<>(path));
            return;
        }

        for (int i = 0; i < nums.length; i++) {
            if (!used[i]) {
                path.add(nums[i]);
                used[i] = true;
                dfs(nums, depth + 1, path, used);
                used[i] = false;
                path.remove(path.size() - 1);
            }
        }
    }
}
